package com.ruoyi.web.controller.demo.controller;

import java.util.ArrayList;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ruoyi.web.controller.demo.bean.Document;
import com.ruoyi.web.controller.demo.bean.Documents;
/**
 * 表单相关
 * 
 * @author ruoyi
 */
@Controller
@RequestMapping("/demo/dyn_obj")
public class DynObjectController
{
    private String prefix = "demo/form";
    
    @GetMapping("/list")
    public String getPage(Model model) {
        Documents  docs = new Documents();
        docs.setDocument(new ArrayList<Document>());
        docs.setId(12);
        model.addAttribute("documents",new Documents());
        return prefix + "/dyn_obj";
    }

    @PostMapping("/save")
    public String save(@ModelAttribute("documents") Documents docs) {
        if(docs.equals(null))
        {
            System.out.println("Bye");
        }
        else {
            System.out.println("Error");
            System.out.println(docs.getId());
            System.out.println(docs.getDocument().size());
        }
        return prefix + "/save";
    }
}
